<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">


    <link rel="icon" href="/favicon.ico" type="image/ico">
    <title>理工花云</title>
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
    <!--<link rel="stylesheet" href="/bootstrap/bootstrap-table/bootstrap-table.css">-->

    <script src="/js/jquery.min.js"></script>
    <script src="/js/jquery.zclip.js"></script>
    <script src="/bootstrap/js/bootstrap.min.js"></script>
    <!--<script src="/bootstrap/bootstrap-table/bootstrap-table.js"></script>-->
    <!--<script src="/bootstrap/bootstrap-table/bootstrap-table-zh-CN.js"></script>-->
    <script src="/webuploader/webuploader.js"></script>

    <style>
        a{
            font-family: "微软雅黑";
            cursor: pointer;
        }
        a.list-group-item:hover{
            background-color: rgba(51, 150, 200, 0.8);
        }
        tr{
            font-family: "微软雅黑";
        }
        .blur {
            filter: url(blur.svg#blur); /* FireFox, Chrome, Opera */
            -webkit-filter: blur(7px); /* Chrome, Opera */
            -moz-filter: blur(7px);
            -ms-filter: blur(7px);
            filter: blur(7px);
            filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius=7, MakeShadow=false); /* IE6~IE9 */
        }
        .loading {
            width: 100%;
            height: 100%;
            position: fixed;
            top: 0%;
            left: 0%;
            line-height: 56px;
            background: #000;
            color: #fff;
            padding-left: 60px;
            font-size: 15px;
            opacity: 0.7;
            z-index: 9999;
            filter: progid:DXImageTransform.Microsoft.Alpha(opacity=70);
        }
    </style>

<body>
    <div id="loading" class="loading" style="display: none;">
        <div style="background:url(images/loading.gif) no-repeat 10px 50%;
            width:56px;
            height:56px;
            position: absolute;
            top:50%;
            left:40%;
            ">
        </div>
        <p style="position: absolute;top:50%;left:45%;">文件生成中，请稍候……</p>
    </div>
    <div id="imgbackground" class="blur" style="background: url('images/bg1.jpg');top:0; position: fixed;width: 100%;height: 100%;z-index: -1;">
    </div>
    <div id="container" class="container" style="width: 90%;margin-top:20px;margin-bottom: 20px; background-color: rgba(255,255,255,0.7);border-radius: 10px;">
        <div class="header clearfix" style="margin: 0px; ">
            <img src="/images/pan-top.png" style="max-height: 50px;">
            <span>
                <ul class="nav nav-pills pull-right" style="margin-top: 10px;">
                    <li role="presentation"><a id="userLName" href="/" th:text="${author}" style="color: firebrick;background: unset;"></a></li>
                    <li id="homeBtn" role="presentation"><a href="/">主页</a></li>
                    <li id="contactBtn" role="presentation" ><a data-toggle="modal" data-target="#donateDlg">捐助</a></li>
                    <li id="quitBtn" role="presentation"><a style="cursor: pointer">退出</a></li>
                </ul>
            </span>
        </div>

        <div class="row" style="margin-top: 15px;">
            <div class="col-lg-6">
                <div class="btn-group" role="group" aria-label="...">
                    <button class="btn btn-default" data-toggle="modal" data-target="#uploadModal"><i class="glyphicon glyphicon-upload"></i>  上传文件</button>
                    &nbsp;&nbsp;
                </div>
                <button class="btn btn-default" data-toggle="modal" data-target="#createDirDlg" ><i class="glyphicon glyphicon-folder-open"></i> 新建文件夹</button>
                &nbsp;&nbsp;
                <button class="btn btn-default" onclick="refreshUserFileList();" ><i class="glyphicon glyphicon-refresh"></i> 刷新</button>
            </div>
        </div>
        <br/>
        <!-- /.row -->

        <ol id="breadcrumb" class="breadcrumb mybc">
            <li><a href="/">根目录</a></li>
        </ol>

        <div id="table_file_bg" class="table-responsive" style="max-height: 500px;overflow: auto;">
            <table id="table_filelist" class="table table-hover" >
                <thead>
                <tr>
                    <th style="width: 35px;vertical-align: middle;"></th>
                    <th>文件</th>
                    <th>大小</th>
                    <th>修改时间</th>
                    <th></th>
                    <th></th>
                    <th>操作</th>
                    <th></th>
                    <th></th>
                </tr>
                </thead>
            </table>
        </div>


        <div class="modal fade" id="uploadModal" role="dialog">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">上传文件</h4>
                    </div>
                    <div class="modal-body">
                        <div id="file_drop_target" style="font-size: 20px;">
                            <h2 id="upload_file_path">请选择要上传的文件</h2>
                            <br/><br/>
                            <button id="pickerbtn" class="btn btn-info btn-lg active">选择文件
                                <button id="picker" class="hide"  multiple></button>
                            </button>
                            &nbsp;&nbsp;
                            <button id="uploadbtn" class="btn btn-info btn-lg active">开始上传
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="donateDlg" role="dialog">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">捐助我们</h4>
                    </div>
                    <div class="modal-body" style="text-align: center;">
                        <img src="/images/cf_code.jpg" style="max-height: 350px;display: inline-block">
                        <img src="/images/jfz_code.jpg" style="max-height: 350px;display: inline-block">
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="createDirDlg" role="dialog">
            <div class="modal-dialog modal-lg" style="width:60%;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">新建文件夹</h4>
                    </div>
                    <div  class="modal-body" style="text-align: center;">
                        <h4 style="text-align: left;">输入新文件夹的名字：</h4>
                        <input id="newDirText" type="text" class = "form-control" data-options="required:true" >
                        <br>
                        <button id="confirmDirBtn" class="btn btn-primary">确定</button>
                        <button id="closeDirBtn" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="getcodeDlg" role="dialog">
            <div class="modal-dialog modal-lg" style="width:60%;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">获取下载码</h4>
                    </div>
                    <div  class="modal-body" style="text-align: left;">
                        <div style="text-align: center;">
                            <img src="/images/bt.gif" style="height: 100px;display: inline-block;vertical-align: bottom;">
                            <img src="/images/cf_code.jpg" style="max-height: 200px;display: inline-block">
                            <img src="/images/jfz_code.jpg" style="max-height: 200px;display: inline-block">
                            <img src="/images/bt.gif" style="height: 100px;display: inline-block;vertical-align: bottom;">
                            <h3 style="margin-top:10px;font-family: '微软雅黑';">开发者好久没吃饭了，小主施舍点嘛……</h3>
                        </div>
                        <br>
                        <h4>要分享的文件：
                            <span id="shareSelectedFile" style="font-family: '微软雅黑';"></span>
                        </h4>
                        <h4 style="text-align: left;">下载地址：</h4>
                        <span style="position: relative;"><a id="shareLink" target="_blank"></a></span>
                        <br>
                        <div style="margin-top: 10px;text-align: center;">
                            <button id="copyLinkBtn" class="btn btn-primary">复制链接</button>
                            <button id="closeLinkBtn" class="btn btn-default" data-dismiss="modal">取消分享</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="moveDlg" role="dialog" data-backdrop="static">
            <div class="modal-dialog modal-lg" style="width: 45%;height: 30%;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">移动文件</h4>
                    </div>
                    <div class="modal-body" >
                        <p id="moveSelectedFile" style="font-family: '微软雅黑';"></p>
                        <ol id="breadcrumbmove" class="breadcrumb mybc">
                            <li><a href="/">根目录</a></li>
                        </ol>
                        <div id="file_list_group" class="list-group">
                            <!--<a class="list-group-item active">根目录</a>-->
                            <!--<a href="#" class="list-group-item active">复制</a>-->
                            <!--<a href="#" class="list-group-item">图像的数量</a>-->
                        </div>
                        <div style="margin-top: 10px;text-align: center;">
                            <button id="setMoveBtn" class="btn btn-primary">确定</button>
                            <button id="closeMoveBtn" class="btn btn-default" data-dismiss="modal">取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!--<footer class="footer" style="margin: 0px; margin-top: 40px;">-->
            <!--<p style="text-align: center; font-family: '微软雅黑'; color: red;">-->
                <!--异想家、国花制作，新年贺礼-->
            <!--</p>-->
        <!--</footer>-->
    </div>

    <script>
        $(function() {
            // 不支持ie浏览器
            if(isIE()==true){
                alert("网站不支持ie内核的浏览器，请使用Chrome内核的浏览器，现在为您退出！");
                $("#quitBtn").click();
                window.opener=null;
                window.open('','_self');
                window.close();
            }
            $("#userLName").text("您好，" + $("#userLName").text());
            // 刷新用户文件列表
            refreshUserFileList();
        });

        // 根目录路径
        var rootUserPath="/";
        // 当前用户路径
        var nowUserPath="/";
        // 当前用户路径
        var nowMovePath="/";
        // 要移动的文件名
        var moveFile={name:"",folder:false};

        // 文件夹标识
        var folder_label = "文件夹";

        $('#quitBtn').click(function (e) {
            $.ajax({
                type : "GET",
                url : "/quit",
                dataType : "text",
                success : function(data) {
                    window.location.href ="/";
                }
            });
        });

        $('#pickerbtn').click(function () {
            $('#picker input[type="file"]').click();
        });

        var uploader = WebUploader.create({
            // swf文件路径
            swf: 'webuploader/Uploader.swf',
            // 文件接收服务端。
            server: '/upload',
            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker',
            resize: false,                               // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            duplicate:true,                              //是否可重复选择同一文件
            threads: 5,
            fileNumLimit: 10,                             // 发送限制单文件
            fileSingleSizeLimit: 20000 * 1024 * 1024,    // 20000M
            fileVal:"file"                               //指明参数名称，后台也用这个参数接收文件
        });
        // // 选择了文件后，在文件被添加进队列前
        // uploader.on( 'beforeFileQueued', function( file ) {             // 发送限制单文件
        //     var fnum = uploader.getFiles().length;                        // 如果有文件在队列中
        //     if(fnum>0) uploader.reset();                                  // 清除队列
        // });
        // 当有文件被添加进队列的时候
        uploader.on( 'fileQueued', function( file ) {
            // $('#upload_file_path').val(file.name);
            // document.getElementById('upload_file_path').innerHTML = file.name;
            $('#upload_file_path').append( '<div id="' + file.id + '" class="item">' +
                '<span class="info">文件： ' + file.name + '</span>' +
                '<span class="state">&nbsp;等待上传...</span>' +
                '</div>' );
        });
        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<br/><br/><div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
            }
            $li.find('span.state').text('   上传中');
            $percent.css( 'width', percentage * 100 + '%' );
        });
        uploader.on( 'error', function( type ) {             // 选择文件出错
            if(type=="F_EXCEED_SIZE"){
                alert("附件不能大于20G");
            }
        });
        uploader.on( 'uploadComplete', function( file ) {
            // $( '#'+file.id ).find('.progress').fadeOut();
            // $( '#'+file.id ).fadeOut();

            var nowStates = uploader.getStats();
            // uploader.reset();
            // uploader.removeFile(file.id,true);

            if(nowStates.progressNum==0) {
                if(nowStates.uploadFailNum!=0) {
                    alert(nowStates.uploadFailNum + '个文件上传失败！');
                    $('#uploadModal').modal('hide');
                    refreshUserFileList();
                }
                if(nowStates.successNum==uploader.getFiles().length){
                    // alert(nowStates.successNum + '个文件上传成功！');
                    alert('所有文件成功上传！');
                    $('#uploadModal').modal('hide');
                    refreshUserFileList();
                }
                $('#upload_file_path').html("请选择要上传的文件");
                uploader.reset();
            }
        });
        uploader.on( 'uploadAccept', function( file, response ) {
            if ( response.success==false ) {
                // 通过return false来告诉组件，此文件上传有错。
                alert('上传失败\r\n'+response.msg);
                $( '#'+file.file.id ).find('.state').text('   上传失败，失败原因：'+response.msg);
            }
            else{
                $( '#'+file.file.id ).find('.state').text('   上传成功');
                // $("#output_table").html();

            }
        });

        $('#uploadbtn').on( 'click', function() {
            uploader.options.formData.path=nowUserPath;
            uploader.upload();
        });

        // 刷新文件列表
        function refreshUserFileList() {
            var cell_start = 1;
            var rowobj_a_start = 0;

            var title_list = $("#breadcrumb");
            title_list.empty();
            title_list.append('<li><a href="/">根目录</a></li>');
            // 获取文件夹层级
            var folderList = nowUserPath.split("/");
            var folderListLen = folderList.length;
            // 清除空的切片
            for(var i=0;i<folderListLen;i++){
                if(folderList[i]==""){
                    folderList.splice(i,1);
                }
            }
            if(nowUserPath != "/"){
                // 不是根目录的情况下，写入文件层级
                for(var i=0;i<folderList.length;i++){
                    if(i != (folderList.length-1)) {
                        title_list.append('<li><a onclick="jumpToUpperPath(this.innerText)">'+ folderList[i] + '</a></li>');
                    }
                    // 最后一层的时候不触发事件
                    else{title_list.append('<li class="active" style="font-family: \'微软雅黑\';" onclick=" ;">'+ folderList[i] + '</li>');}

                }
            }

            $.ajax({
                type: "POST",
                url: "/userfilelist",
                data: {path:nowUserPath},
                dataType: "json",
                success: function (data) {
                    // 将现在的表内容存储并清空
                    var oTabNow = document.getElementById('table_filelist');
                    var nowTabRowLen = oTabNow.rows.length;
                    for (var i = 1; i < nowTabRowLen; i++) {
                        var rowObj = oTabNow.rows[1];
                        if(isIE()){
                            rowObj.parentNode.removeChild(rowObj);
                        }
                        else {
                            rowObj.remove();
                        }
                    }

                    var hdfsMode = false;
                    var downloadlist = new Array();
                    if(data.length > 0) {
                        hdfsMode = data[0].link=="HDFS" ? true : false;
                    }
                    for (var i = 0; i < data.length; i++) {
                        var rowObj = oTabNow.insertRow(oTabNow.rows.length); // 添加一行
                        // 判断是否为目录，是目录则去掉“/”
                        if(data[i].size.indexOf("Directory") != -1) {
                            data[i].name = data[i].name.replace("/","");
                            data[i].size = folder_label;
                            rowObj.insertCell(0).innerHTML = '<img src="images/p_folder.png" style="height: 25px;">';
                        }
                        else{
                            rowObj.insertCell(0).innerHTML = '<img src="images/p_file.png" style="height: 25px;">';
                        }

                        rowObj.insertCell(cell_start).innerHTML = '<a>'+data[i].name+'</a>';
                        rowObj.insertCell(cell_start+1).innerHTML = data[i].size;
                        rowObj.insertCell(cell_start+2).innerHTML = data[i].time;
                        rowObj.insertCell(cell_start+3).innerHTML = '<a>分享</a>';
                        rowObj.insertCell(cell_start+4).innerHTML = '<a>移动</a>';
                        rowObj.insertCell(cell_start+5).innerHTML = '<a>下载</a>';
                        rowObj.insertCell(cell_start+6).innerHTML = '<a>重命名</a>';
                        rowObj.insertCell(cell_start+7).innerHTML = '<a>删除</a>';
                        downloadlist.push(data[i].link);
                        // 文件夹操作响应事件
                        rowObj.getElementsByTagName('a')[0].onclick = function () {
                            var tempIdx = this.parentNode.parentNode.rowIndex;
                            // 如果已经处于重命名状态，就退出
                            var tempName = oTabNow.rows[tempIdx].cells[cell_start].innerHTML;
                            if(tempName.indexOf("div") != -1) return;

                            // 去掉html元素
                            tempName = tempName.replace("<a>","");
                            tempName = tempName.replace("</a>","");

                            // 判断是否为目录
                            var tempSize = oTabNow.rows[tempIdx].cells[cell_start+1].innerHTML;
                            if(tempSize.indexOf(folder_label) != -1) {
                                nowUserPath += tempName + "/";
                                refreshUserFileList();
                            }
                            // 文件的话就下载
                            else{oTabNow.rows[tempIdx].getElementsByTagName('a')[3].onclick();}
                        }
                        // 分享操作响应事件
                        rowObj.getElementsByTagName('a')[1].onclick = function (){
                            var tempIdx = this.parentNode.parentNode.rowIndex;
                            // 如果已经处于重命名状态，就退出
                            var tempName = oTabNow.rows[tempIdx].cells[cell_start].innerHTML;
                            if(tempName.indexOf("div") != -1) return;

                            // 去掉html元素
                            tempName = tempName.replace("<a>","");
                            tempName = tempName.replace("</a>","");

                            // 判断是否为目录
                            var tempSize = oTabNow.rows[tempIdx].cells[cell_start+1].innerHTML;
                            // 是目录的时候
                            if(tempSize.indexOf(folder_label) != -1) {
                                alert("文件夹不支持分享哦！");
                                return;
                            }

                            $.ajax({
                                type: "POST",
                                url: "/getcode",
                                data: {fileName: tempName,path:nowUserPath},
                                dataType: "json",
                                success: function (data) {
                                    if(data.success){
                                        var rootLink = window.location.host;
                                        var tgLink = "http://"+rootLink + "/sharefile?code=" + data.msg;
                                        // alert(tgLink);
                                        $('#shareLink').text(tgLink);
                                        $('#shareLink').attr({href:tgLink});
                                        $('#shareSelectedFile').text(tempName);
                                        $('#getcodeDlg').modal('show');
                                    }
                                }
                            });

                        }
                        // 移动操作响应事件
                        rowObj.getElementsByTagName('a')[2].onclick = function (){
                            var tempIdx = this.parentNode.parentNode.rowIndex;
                            // 如果已经处于重命名状态，就退出
                            var tempName = oTabNow.rows[tempIdx].cells[cell_start].innerHTML;
                            if(tempName.indexOf("div") != -1) return;

                            // 去掉html元素
                            tempName = tempName.replace("<a>","");
                            tempName = tempName.replace("</a>","");

                            $("#moveDlg").modal('show');

                            // 判断是否为目录
                            var tempSize = oTabNow.rows[tempIdx].cells[cell_start+1].innerHTML;
                            // 是目录的时候
                            if(tempSize.indexOf(folder_label) != -1) {
                                $("#moveSelectedFile").text("要移动的文件夹："+ tempName);
                                moveFile.folder=true;
                            }
                            else{
                                $("#moveSelectedFile").text("要移动的文件夹："+ tempName);
                                moveFile.folder=false;
                            }
                            moveFile.name = tempName;

                            nowMovePath = rootUserPath;
                            listUserFolder(rootUserPath);
                        }
                        // 下载操作响应事件
                        rowObj.getElementsByTagName('a')[3].onclick = function () {
                            var tempIdx = this.parentNode.parentNode.rowIndex;
                            // 如果已经处于重命名状态，就退出
                            var tempName = oTabNow.rows[tempIdx].cells[cell_start].innerHTML;
                            if(tempName.indexOf("div") != -1) return;

                            // 去掉html元素
                            tempName = tempName.replace("<a>","");
                            tempName = tempName.replace("</a>","");

                            // 判断是否为目录
                            var tempSize = oTabNow.rows[tempIdx].cells[cell_start+1].innerHTML;
                            // 是目录的时候
                            if(tempSize.indexOf(folder_label) != -1) {
                                alert("文件夹不支持下载哦！");
                                return;
                            }

                            // 不支持ie下载
                            if(isIE()==true){
                                alert("不支持ie内核的浏览器下载，请使用Chrome内核的浏览器下载！");
                                return;
                            }

                            // hdfs模式使用请求下载
                            // 普通模式直接下载
                            if(hdfsMode)
                            {
                                $("#loading").show();
                                $.ajax({
                                    type: "POST",
                                    url: "/download",
                                    data: {fileName: tempName,path:nowUserPath},
                                    dataType: "json",
                                    success: function (data) {
                                        $("#loading").hide();
                                        if(data.success){allDownloadFile(data.msg,tempName);}
                                    }
                                });
                            }
                            else {
                                window.downloadFile(downloadlist[tempIdx - 1]);
                            }
                        }
                        // 重命名操作响应事件
                        rowObj.getElementsByTagName('a')[4].onclick = function () {
                            var tempIdx = this.parentNode.parentNode.rowIndex;
                            var tempName = oTabNow.rows[tempIdx].cells[cell_start].innerHTML;
                            var rowRename = oTabNow.rows[tempIdx].cells[cell_start];
                            // 如果已经处于重命名状态，就退出重命名
                            if(tempName.indexOf("div") != -1) return;
                            // 去掉html元素
                            tempName = tempName.replace("<a>","");
                            tempName = tempName.replace("</a>","");
                            // 进入重命名模式
                            rowRename.innerHTML=
                                '<div class="input-group">'+
                                    '<input  id="' + tempName + 'Id' +'" style="width: 120px; height: 29px" type="text" class = "form-control" data-options="required:true " value="'+tempName+'">&nbsp;&nbsp;' +
                                    '<button id="' + tempName + 'BtnOK' +'" class = "glyphicon glyphicon-ok" style="height: 29px"></button>&nbsp;&nbsp;' +
                                    '<button id="' + tempName + 'BtnRemove' +'" class = "glyphicon glyphicon-remove" style="height: 29px"></button>' +
                                '</div>'
                            // 确认重命名
                            rowRename.getElementsByTagName('button')[0].onclick = function (){
                                // rowRename.innerHTML = this.parentNode.childNodes[0].value;
                                var oldName = this.parentNode.childNodes[0].defaultValue;
                                var newName = this.parentNode.childNodes[0].value;
                                if(newName=="") {rowRename.getElementsByTagName('button')[1].onclick();return;}
                                // 判断是否为目录
                                var tempSize = oTabNow.rows[tempIdx].cells[2].innerHTML;
                                // 是目录的时候
                                if(tempSize.indexOf(folder_label) != -1) {
                                    $.ajax({
                                        type: "POST",
                                        url: "/filerename",
                                        data: {oldName : "@dir@" , newName : newName, path : nowUserPath + oldName},
                                        dataType: "json",
                                        success: function (data) {
                                            refreshUserFileList();
                                        }
                                    });
                                }
                                else {
                                    $.ajax({
                                        type: "POST",
                                        url: "/filerename",
                                        data: {oldName : oldName , newName : newName,path: nowUserPath},
                                        dataType: "json",
                                        success: function (data) {
                                            refreshUserFileList();
                                        }
                                    });
                                }
                            }
                            // 取消重命名
                            rowRename.getElementsByTagName('button')[1].onclick = function (){
                                rowRename.innerHTML = "<a>" + this.parentNode.childNodes[0].defaultValue + "</a>";
                            }
                        }
                        // 删除操作响应事件
                        rowObj.getElementsByTagName('a')[5].onclick = function () {
                            var tempIdx = this.parentNode.parentNode.rowIndex;
                            // 如果已经处于重命名状态，就退出
                            var tempName = oTabNow.rows[tempIdx].cells[cell_start].innerHTML;
                            if(tempName.indexOf("div") != -1) return;

                            // 去掉html元素
                            tempName = tempName.replace("<a>","");
                            tempName = tempName.replace("</a>","");

                            // 判断是否为目录
                            var tempSize = oTabNow.rows[tempIdx].cells[cell_start+1].innerHTML;
                            if(tempSize.indexOf(folder_label) != -1) {
                                $.ajax({
                                    type: "POST",
                                    url: "/filedelete",
                                    data: {fileName:"@dir@", path: nowUserPath + tempName},
                                    dataType: "json",
                                    success: function (data) {
                                        refreshUserFileList();
                                    }
                                });
                            }
                            else{
                                $.ajax({
                                    type: "POST",
                                    url: "/filedelete",
                                    data: {fileName:tempName,path: nowUserPath},
                                    dataType: "json",
                                    success: function (data) {
                                        refreshUserFileList();
                                    }
                                });
                            }

                        }
                    }
                }
            });
        }

        function jumpToUpperPath(filePathName) {
            // 检查当前路径中是否含有目标路径
            var temp_index = nowUserPath.indexOf(filePathName);
            if(temp_index==-1) return;
            nowUserPath = nowUserPath.slice(0,temp_index) + filePathName +"/";
            refreshUserFileList();
        }

        $('#confirmDirBtn').on( 'click', function() {
            var newFolderName = $('#newDirText').val();
            if(newFolderName=="") return;
            $.ajax({
                type: "POST",
                url: "/dircreate",
                data: {dirName:newFolderName,path:nowUserPath},
                dataType: "json",
                success: function (data) {
                    if(data.success==true){
                        refreshUserFileList();
                    }
                }
            });
            $('#createDirDlg').modal('hide');
        });

        function isIE() { //ie?
            if (!!window.ActiveXObject || "ActiveXObject" in window)
                return true;
            else
                return false;
        }
        //IE浏览器图片保存本地
        function SaveAs5(imgURL) {
            var oPop = window.open(imgURL,"","width=1, height=1, top=5000, left=5000");
            for(; oPop.document.readyState != "complete"; )
            {
                if (oPop.document.readyState == "complete")break;
            }
            oPop.document.execCommand("SaveAs");
            oPop.close();
        }
        // 生成下载连接函数
        function downloadFile(url, fileName_download) {
            try {
                var elemIF = document.createElement("a");
                elemIF.src = url;
                elemIF.href = url;
                elemIF.download = fileName_download;
                elemIF.style.display = "none";
                document.body.appendChild(elemIF);
                elemIF.click();
            } catch (e) {
                alert(e)
            }
            // window.open(url);
        }
        // 兼容所有浏览器的下载接口
        function allDownloadFile(url, fileName_download){
            if(isIE()){
                SaveAs5(url);
            }
            else{
                downloadFile(url, fileName_download);
            }
        }

        $('#copyLinkBtn').zclip({
                path: 'js/ZeroClipboard.swf',
                copy: function(){ 　　　　　　　　　　        // 复制内容
                    return $('#shareLink').text();  　       // shareLink 内容
                },
                afterCopy: function(){                        // 复制成功
                    alert('已复制到剪贴板！');
                }
        });

        // 移动到里面的跳转上级文件夹
        function jumpToMoveUpperPath(filePathName) {
            // 检查当前路径中是否含有目标路径
            var temp_index = nowMovePath.indexOf(filePathName);
            if(temp_index==-1) return;
            nowMovePath = nowMovePath.slice(0,temp_index) + filePathName +"/";
            listUserFolder(nowMovePath);
        }

        // 根据路径获取文件夹结构
        function listUserFolder(path_in) {
            var title_list = $("#breadcrumbmove");
            title_list.empty();
            title_list.append('<li><a onclick="nowMovePath=rootUserPath;listUserFolder(nowMovePath);">根目录</a></li>');
            // 获取文件夹层级
            var folderList = nowMovePath.split("/");
            var folderListLen = folderList.length;
            // 清除空的切片
            for(var i=0;i<folderListLen;i++){if(folderList[i]==""){folderList.splice(i,1);}}
            if(nowMovePath != "/"){
                // 不是根目录的情况下，写入文件层级
                for(var i=0;i<folderList.length;i++){
                    if(i != (folderList.length-1)) {
                        title_list.append('<li><a onclick="jumpToMoveUpperPath(this.innerText)">'+ folderList[i] + '</a></li>');
                    }
                    // 最后一层的时候不触发事件
                    else{title_list.append('<li class="active" style="font-family: \'微软雅黑\';" onclick=" ;">'+ folderList[i] + '</li>');}

                }
            }
            $("#file_list_group").html("");

            $.ajax({
                type: "POST",
                url: "/userfilelist",
                data: {path: path_in},
                dataType: "json",
                success: function (data) {
                    var activeObj = $("#file_list_group");
                    for (var i = 0; i < data.length; i++) {
                        // 判断是否为目录，是目录则去掉“/”
                        if (data[i].size.indexOf("Directory") != -1) {
                            data[i].name = data[i].name.replace("/", "");
                            activeObj.append('<a class="list-group-item">' +
                                '<img src="images/p_folder.png" style="height: 25px;margin-right: 15px;">' +
                                data[i].name + '</a>');
                        }
                    }

                    activeObj.find('a').each(function(index) {
                        $(this).on('click', function () {
                            nowMovePath += $(this).text() + "/";
                            listUserFolder(nowMovePath);
                        });
                    });
                }
            });
        }

        $('#setMoveBtn').click(function (){
            var oldpath = nowUserPath;
            var newpath = nowMovePath;
            $.ajax({
                type: "POST",
                url: "/filemove",
                data: {
                    fileName: ((moveFile.folder==true)?"@dir@":moveFile.name),
                    oldPath:((moveFile.folder==true)?(oldpath+moveFile.name):oldpath),
                    newPath:newpath
                },
                dataType: "json",
                success: function (data) {
                    if(data.success==true){
                        alert("移动成功！");
                    }
                    else {
                        alert("移动失败！请稍候再试！");
                    }
                    $("#moveDlg").modal('hide');
                    refreshUserFileList();
                }
            });
        });


    </script>
</body>

</html>
